#include<iostream>
#include<cstdio>
using namespace std;
bool lie[100],yz[100],zy[100];
int num,n,a[100];
void print(){
	for(int i=1;i<=n;i++){
		cout<<a[i]<<" ";
	}
	cout<<"\n";
}
int search(int i){
    for(int j=1;j<=n;j++){
        if(!lie[j]&&!yz[i+j]&&!zy[i-j+n]){
        	a[i]=j;
 			lie[j]=true;
			yz[i+j]=true;
			zy[i-j+n]=true;
			if(i==n){
				num++;
				if(num<=3)print();
			}
   			  else search(i+1);
   			  //a[i]=0;
			lie[j]=false;
			yz[i+j]=false;
			zy[i-j+n]=false;
		}
	}
}
int main(){
	//freopen ("queen.in","r",stdin);
	//freopen ("queen.out","w",stdout);
	cin>>n;
	search(1);
	cout<<num;
	return 0;
}
